package com.itsol.pizza.dao;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.itsol.pizza.entity.Pizza;

@Repository
@SuppressWarnings({"unchecked"})
public class PizzaDAOImpl implements PizzaDAO {

	@Autowired 
	private SessionFactory sessionFactory;
	
	/**
	 * @Transactional annotation below will trigger Spring Hibernate transaction manager to automatically create
	 * a hibernate session. See src/main/webapp/WEB-INF/servlet-context.xml
	 */
	@Transactional
	public List<Pizza> findAll() {
		Session session = sessionFactory.getCurrentSession();
	    return session.createQuery("from Pizza").list();
	}

}
